package fnic.prehand.esagent.ap_measure_new2;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.action.update.UpdateRequestBuilder;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.index.query.FilterBuilder;
import org.elasticsearch.index.query.FilterBuilders;
import org.elasticsearch.script.ScriptService.ScriptType;
import org.elasticsearch.search.SearchHits;






import fnic.prehand.esagent.EsAgent;

public class EsUpdate extends EsAgent{
	private static final Logger logger = Logger.getLogger(EsUpdate.class);
	private static final String cindex=config.getAp_indexName();
//	private static final String stainfo=config.getAptype_stainfo();
	private static final String stainfo_history=config.getAptype_stainfo_his();
	private static final String approperty=config.getAptype_approperty();
	private static final String FIELD_APINFO = "apinfo";
	private static final String FIELD_STAINFO = "stainfo";
	private static final String FIELD_APLEVEL = "ap_logical";
	
	public boolean upsertLogin(String apmac, String stamac, String login){		
		boolean needIncr_newuser = true;
		if(stamac==null || apmac == null){
			logger.error("login msg illegal, apmac:"+apmac+", stamc:"+stamac);
			return false;
		}
		
		Map<String ,Object> initmaps = new HashMap<String ,Object>();
		initmaps.put("sta_mac", stamac);
		initmaps.put("sta_up", 0);
		initmaps.put("sta_down", 0);
		initmaps.put("sta_login", login);

		boolean apExist = apInService(apmac);
		if (!apExist) {
			// 设置ap登录时间为login
			Map<String ,Object> loginmaps = new HashMap<String ,Object>();
			loginmaps.put("ap_mac", apmac);

			boolean aploginfg = APHTTPEsAgent.upsertLogin(apmac, login, loginmaps);
			if(!aploginfg){
				return false;
			}
			logger.info("ap login(in sta login): " + login);
		}

		// 需要隐式logout，将之前的记录移到history中
		// String oldap = whichApStaLocate(stamac, true);
		String oldap = staLocateAP2(stamac);
		if (oldap != null && !oldap.equals(apmac)) {
			updateLogout(oldap, stamac, login);
		}
		
	
		List<Map<String, Object>> staMaps = stainfosInAp(apmac);
		if(staMaps == null){
			staMaps = new ArrayList<Map<String, Object>>();
			staMaps.add(initmaps);
		}else{
			if(apmac.equals(oldap)){
				Map<String, Object> stamap = locateStainfoInAP(staMaps, stamac, false);
				if(stamap!=null){
					stamap.remove("sta_login");
					stamap.put("sta_login", login);	
					needIncr_newuser = false;
				}else{
					staMaps.add(initmaps);
				}
/*				Iterator<Map<String, Object>> itor = staMaps.iterator();
				int index = 0;
				while(itor.hasNext()){
					Map<String, Object> item  = itor.next();
					if(((String)item.get("sta_mac")).equals(stamac)){
						break;
					}
					index++;
				}
				if(index<staMaps.size()){
					Map<String, Object> stamap = staMaps.get(index);
					//更新sta的Login字段
					stamap.remove("sta_login");
					stamap.put("sta_login", login);				
				}else{
					staMaps.add(initmaps);
				}*/
			}else{
				staMaps.add(initmaps);
			}
		}

		
		UpdateRequestBuilder updateRequest = client.prepareUpdate(cindex, approperty, apmac).setDoc(FIELD_STAINFO, staMaps);
		UpdateResponse updatersp;
		try{
			updatersp = updateRequest.execute().actionGet();
		}catch(ElasticsearchException e){
			logger.error("sta login fail: "+e.getMessage()+",  apmac:"+apmac+", stamac:"+stamac);
//			e.printStackTrace();
			return false;
		}
		

	    long _version = updatersp.getVersion();  
	    logger.info("sta["+stamac+"] login in ap["+apmac+"]succeed, version:"+_version);
	    if(needIncr_newuser){
	    	updateAPStaNum(apmac, 1);
	    }
		return true;
	}
	
	public boolean updateLogout(String apmac, String stamac, String logout){	
		if(stamac==null || apmac == null){
			logger.error("logout msg illegal, apmac:"+apmac+", stamc:"+stamac);
			return false;
		}

		boolean apExist = apInService(apmac);
		if (!apExist) {
			// 设置ap登录时间为login
			Map<String ,Object> loginmaps = new HashMap<String ,Object>();
			loginmaps.put("ap_mac", apmac);
			APHTTPEsAgent.upsertLogin(apmac, logout, loginmaps);
			logger.info("ap login(in sta logout): " + logout);
		}

		// 需要隐式logout，将之前的记录移到history中
		// String oldap = whichApStaLocate(stamac, true);
		String oldap = staLocateAP2(stamac);
		if (oldap != null && !oldap.equals(apmac)) {
			updateLogout(oldap, stamac, logout);
		}
		
	
		List<Map<String, Object>> staMaps = stainfosInAp(apmac);
		if(staMaps == null){
			logger.error("attention!!! sta["+stamac+"] in ap["+apmac+"] logout, but stainfo is empty");
			return false;
		}else{
			if(apmac.equals(oldap)){
				Map<String, Object> stamap = locateStainfoInAP(staMaps, stamac, true);
				if(stamap!=null){
					String login = (String)stamap.get("sta_login");
					stamap.put("sta_logout", logout);
					
					Map<String,Object> appromap = apProperty(apmac);
					if(appromap!=null){
						stamap.put(FIELD_APLEVEL, appromap);
					}
					stamap.put("ap_mac", apmac);
					
					if(login!=null&&logout!=null){
						DateFormat timeformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
						long intrevalSecs = 0;
						try {
							Date logindate = timeformat.parse(login);
							Date logoutdate = timeformat.parse(logout);
							intrevalSecs = (logoutdate.getTime() - logindate.getTime())/1000;
						} catch (ParseException e) {
							logger.error("login/logout dateformat trans error:"+e.getMessage());
						}
						stamap.put("sta_timelength", intrevalSecs); //以秒为单位
					}
					
//					  Calendar ca = Calendar.getInstance();
//				      int year = ca.get(Calendar.YEAR);//获取年份
//				      int month=ca.get(Calendar.MONTH);//获取月份 
//				      int day=ca.get(Calendar.DATE);//获取日

				    
//					String beforethistime = year+"-"+month+"-"+day+" 00:00:00"; 
					String beforethistime = logout.split(" ")[0]+" 00:00:00";
					
					boolean newCustom = true;
					long visitFrq = staHisFreq((String)stamap.get("sta_mac"), beforethistime);
					if(visitFrq>0){
						stamap.put("sta_custom", "old");
					}else{
						stamap.put("sta_custom", "new");
					}
					stamap.put("sta_type", "all");
					staAddHistory(apmac,stamap);
				}else{
					logger.error("attention!!! sta["+stamac+"] in ap["+apmac+"] logout, apmac not match, old apmac["+oldap+"]");
					return false;
				}
/*				Iterator<Map<String, Object>> itor = staMaps.iterator();
				int index = 0;
				while(itor.hasNext()){
					Map<String, Object> item  = itor.next();
					if(((String)item.get("sta_mac")).equals(stamac)){
						break;
					}
					index++;
				}
				if(index<staMaps.size()){
					Map<String, Object> stamap = staMaps.get(index);
					String login = (String)stamap.get("sta_login");
					stamap.put("sta_logout", logout);
					
					Map<String,Object> appromap = apProperty(apmac);
					if(appromap!=null){
						stamap.putAll(appromap);
					}
					stamap.put("ap_mac", apmac);
					
					if(login!=null&&logout!=null){
						DateFormat timeformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
						long intrevalSecs = 0;
						try {
							Date logindate = timeformat.parse(login);
							Date logoutdate = timeformat.parse(logout);
							intrevalSecs = (logoutdate.getTime() - logindate.getTime())/1000;
						} catch (ParseException e) {
							logger.error("login/logout dateformat trans error:"+e.getMessage());
						}
						stamap.put("sta_timelength", intrevalSecs); //以秒为单位
					}
					
					staAddHistory(apmac,stamap);
					staMaps.remove(index);			
				}else{
					logger.error("attention!!! sta["+stamac+"] in ap["+apmac+"] logout, apmac not match, old apmac["+oldap+"]");
					return false;
				}*/
			}else{
				logger.error("attention!!! sta["+stamac+"] in ap["+apmac+"] logout, but ap'stainfo not contains this sta");
				return false;
			}
		}
		
		UpdateRequestBuilder updateRequest = client.prepareUpdate(cindex, approperty, apmac).setDoc(FIELD_STAINFO, staMaps);
		UpdateResponse updatersp;
		
		try{
			updatersp = updateRequest.execute().actionGet();
		}catch(ElasticsearchException e){
			logger.error("logout fail: "+e.getMessage()+",  apmac:"+apmac+", stamac:"+stamac);
//			e.printStackTrace();
			return false;
		}
		
	    // 索引版本  
	    long _version = updatersp.getVersion();  
	    logger.info("sta["+stamac+"] logout in ap["+apmac+"]succeed, version:"+_version);
	    updateAPStaNum(apmac, -1);
		return true;
	}
	
	public boolean updateApFlow(String apmac, long up, long down){	
		long time = System.currentTimeMillis();
		Date date = new Date(time);
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String login_time = dateFormat.format(date);
		
		if(!apInService(apmac)){
			// 设置ap登录时间为login
			Map<String ,Object> loginmaps = new HashMap<String ,Object>();
			loginmaps.put("ap_mac", apmac);
			APHTTPEsAgent.upsertLogin(apmac, login_time, loginmaps);
			logger.info("ap login(in sta login): " + login_time);
		}
		
		UpdateRequestBuilder updateRequest = client.prepareUpdate(cindex, approperty, apmac);
		String script =  "ctx._source.apinfo.ap_upflow += "+up +"; ctx._source.apinfo.ap_downflow += "+down+"; ctx._source.apinfo.ap_totalflow += "+(up+down);	
		UpdateResponse updatersp;
		try{
			updatersp = updateRequest.setScript(script, ScriptType.INLINE).execute().actionGet();
		}catch(ElasticsearchException e){
//			e.printStackTrace();
			logger.error("update ap flow fail: "+e.getMessage()+",  apmac:"+apmac);
			return false;
		}
		
		return true;
	}
	
	public boolean updateStaFlow(String apmac, String stamac, long up, long down){
		boolean needIncr_newuser = true;
		if(stamac==null){
			logger.error("sta flow no stamac");
			return false;
		}
		
		long time = System.currentTimeMillis();
		Date date = new Date(time);
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String login_time = dateFormat.format(date);
				
		// 检查sta是否从新的ap上来，将老的sta记录移除
		// String oldap = whichApStaLocate(stamac, true);
		String oldap = staLocateAP2(stamac);
		if (oldap != null && !oldap.equals(apmac)) {
			updateLogout(oldap, stamac, login_time);
		}

		// 确保新的ap存在
		boolean apExist = apInService(apmac);
		if (!apExist) {
			// 设置ap登录时间为login
			Map<String ,Object> loginmaps = new HashMap<String ,Object>();
			loginmaps.put("ap_mac", apmac);
			APHTTPEsAgent.upsertLogin(apmac, login_time, loginmaps);
			logger.info("ap login(in sta flow): " + login_time);
		}

//		boolean staExist = staExist(stamac);
//		if (!staExist) {
//			upsertLogin(apmac, stamac, login_time);
//			logger.info("sta login(in sta flow): " + login_time);
//		}
		Map<String ,Object> initmaps = new HashMap<String ,Object>();
		initmaps.put("sta_mac", stamac);
		initmaps.put("sta_up", up);
		initmaps.put("sta_down", down);
		initmaps.put("sta_total", up+down);
		initmaps.put("sta_login", login_time);
		
		List<Map<String, Object>> staMaps = stainfosInAp(apmac);
		if(staMaps == null){
			staMaps = new ArrayList<Map<String, Object>>();
			staMaps.add(initmaps);
//			updateAPStaNum(apmac, 1);
		}else{
			if(apmac.equals(oldap)){
				Map<String, Object> stamap = locateStainfoInAP(staMaps, stamac, false);
				if(stamap!=null){
					//更新sta的Login字段
					int upflow = (Integer)stamap.get("sta_up");
					int downflow = (Integer)stamap.get("sta_down");
//					int totalflow = (Integer)stamap.get("sta_total");
					stamap.remove("sta_up");
					stamap.remove("sta_down");
					stamap.put("sta_up", upflow+up);
					stamap.put("sta_down", downflow+down);
					stamap.put("sta_total", upflow+downflow+up+down);
					needIncr_newuser = false;
				}else{
//					updateAPStaNum(apmac, 1);
					staMaps.add(initmaps);
				}
/*				Iterator<Map<String, Object>> itor = staMaps.iterator();
				int index = 0;
				while(itor.hasNext()){
					Map<String, Object> item  = itor.next();
					if(((String)item.get("sta_mac")).equals(stamac)){
						break;
					}
					index++;
				}
				if(index<staMaps.size()){
					Map<String, Object> stamap = staMaps.get(index);
					//更新sta的Login字段
					int upflow = (Integer)stamap.get("sta_up");
					int downflow = (Integer)stamap.get("sta_down");
//					int totalflow = (Integer)stamap.get("sta_total");
					stamap.remove("sta_up");
					stamap.remove("sta_down");
					stamap.put("sta_up", upflow+up);
					stamap.put("sta_down", downflow+down);
					stamap.put("sta_total", upflow+downflow+up+down);
				}else{
					staMaps.add(initmaps);
				}*/
				
			}else{
				staMaps.add(initmaps);
//				updateAPStaNum(apmac, 1);
			}
		}
		
		UpdateRequestBuilder updateRequest = client.prepareUpdate(cindex, approperty, apmac).setDoc(FIELD_STAINFO, staMaps);
		UpdateResponse updatersp;
		try{
			updatersp = updateRequest.execute().actionGet();
		}catch(ElasticsearchException e){
//			e.printStackTrace();
			logger.error("update sta flow fail: "+e.getMessage()+",  apmac:"+apmac+", stamac:"+stamac);
			return false;
		}
		
		if(needIncr_newuser){
			updateAPStaNum(apmac, 1);
		}
		return true;
	}
	
	
	public static boolean staslogoutByAP(String apmac){
		List<Map<String, Object>> staMaps = stainfosInAp(apmac);
		if(staMaps == null){
			logger.info("ap logout without stainfo");
		}else{
			long time = System.currentTimeMillis();
			Date date = new Date(time);
			DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String loginout_time = dateFormat.format(date);
			Iterator<Map<String, Object>> itor = staMaps.iterator();
			
			while(itor.hasNext()){
				Map<String, Object> stamap  = itor.next();
				String login = (String)stamap.get("sta_login");
				stamap.put("sta_logout", loginout_time);
				
				Map<String,Object> appromap = apProperty(apmac);
				if(appromap!=null){
					stamap.put("ap_logical", appromap);
				}
				stamap.put("ap_mac", apmac);
				
				if(login!=null&&loginout_time!=null){
					DateFormat timeformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					long intrevalSecs = 0;
					try {
						Date logindate = timeformat.parse(login);
						Date logoutdate = timeformat.parse(loginout_time);
						intrevalSecs = (logoutdate.getTime() - logindate.getTime())/1000;
					} catch (ParseException e) {
						logger.error("login/logout dateformat trans error:"+e.getMessage());
					}
					stamap.put("sta_timelength", intrevalSecs); //以秒为单位
				}
				staAddHistory(apmac,stamap);
			}
		}
		return true;
	}
	
	
	private Map<String, Object> locateStainfoInAP(List<Map<String, Object>> staMaps, String stamac, boolean delfg){
		Map<String, Object> stamap = null;
		Iterator<Map<String, Object>> itor = staMaps.iterator();
		int index = 0;
		while(itor.hasNext()){
			Map<String, Object> item  = itor.next();
			if(((String)item.get("sta_mac")).equals(stamac)){
				break;
			}
			index++;
		}
		if(index<staMaps.size()){
			stamap = staMaps.get(index);
			if(delfg){
				staMaps.remove(index);
			}
		}

		return stamap;	
	}
	
	private boolean updateAPStaNum(String apmac, int increase){
		UpdateRequestBuilder updateRequest = client.prepareUpdate(cindex, approperty, apmac);
		String script =  "ctx._source.apinfo.ap_stanum += "+increase;   //更新FIELD_APINFO中sta个数
		UpdateResponse updatersp;
		try{
			updatersp = updateRequest.setScript(script, ScriptType.INLINE).execute().actionGet();
		}catch(ElasticsearchException e){
//			e.printStackTrace();
			logger.error("update stanum fail: "+e.getMessage()+",  apmac:"+apmac);
			return false;
		}
	    // 索引名称  
	    String _index = updatersp.getIndex();  
	    // type名称  
	    String _type = updatersp.getType();  
	    // 文档ID  
	    String _id = updatersp.getId();  
	    // 索引版本  
	    long _version = updatersp.getVersion();  
	    
//	    System.out.println("update sta num succeed, index:" +_index+  
//	    		           "  type:" +_type+
//	    		           "  id:"   +_id+
//	    		           "  version:"+_version);
	    
	    return true;
	}

/*	private String staLocateAP(String sta){
		GetResponse getResponse = client.prepareGet(cindex, stainfo, sta).setFields("ap_mac").execute().actionGet();
		if(!getResponse.isExists()){
//			System.out.println("staGet find stamac:"+sta+" fail");
			return null;
		}else{
			return (String)getResponse.getField("ap_mac").getValue();
		}
	}*/
	
	private String staLocateAP2(String sta){
		SearchResponse response;
		try{
			response = client.prepareSearch(cindex)  
	            .setTypes(approperty)  
	            .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)  
	            .setPostFilter(FilterBuilders.nestedFilter(FIELD_STAINFO, FilterBuilders.termFilter("sta_mac", sta)))
	            .setExplain(true)  
	            .execute()  
	            .actionGet(); 
		}catch(Exception e){
			logger.error("[staLocateAP2] get sta in other ap fail:"+e.getMessage());
			return null;
		}
		long active_stanum = response.getHits().getTotalHits();
		if(active_stanum == 0){
			return null;
		}
		if(active_stanum > 1){
			logger.error("attention!!!sta in more one aps");
		}
		
		//只返回第一个命中的
		SearchHits hits = response.getHits(); 
		return hits.getAt(0).getId();
	}
	
	private boolean apInService(String apmac)
	{
		GetResponse getResponse = client.prepareGet(cindex, approperty, apmac).execute().actionGet();
		if(!getResponse.isExists()){
			logger.error("get ap[" +apmac+"] in service fail, ap not exist!");
			return false;
		}
		Map<String, Object> apMaps = getResponse.getSourceAsMap();
		if(apMaps!=null&&apMaps.containsKey(FIELD_APINFO)){
			return true;
		}else{
			logger.error("get ap[" +apmac+"]  in service fail,  apinfo not exist!");
			return false;
		}
	}
	
/*	private boolean staExist(String sta){
		当前状态查找sta记录
		GetResponse getResponse = client.prepareGet(cindex, stainfo, sta).execute().actionGet();
		if(!getResponse.isExists()){
			return false;
		}
		return true;
	}*/
	
	private static List<Map<String, Object>> stainfosInAp(String apmac){
		/*当前状态查找sta记录*/
		GetResponse getResponse = client.prepareGet(cindex, approperty, apmac).execute().actionGet();
		Map<String, Object> apMaps = getResponse.getSourceAsMap();
		if(apMaps == null || !apMaps.containsKey(FIELD_STAINFO)){
			logger.error("get stainfos in ap[" +apmac+"]  fail,  stainfo not exist!");
			return null;
		}
		
		return (List<Map<String, Object>>) apMaps.get(FIELD_STAINFO);
	}
	
	public static Map<String, Object> apProperty(String apmac){ 
		/*当前状态查找sta记录*/
		GetResponse getResponse = client.prepareGet(cindex, approperty, apmac).execute().actionGet();
		Map<String, Object> apMaps = getResponse.getSourceAsMap();
		if(apMaps == null || !apMaps.containsKey(FIELD_APLEVEL)){
			logger.error("get ap logical info in ap[" +apmac+"]  fail,  ap level not exist!");
			return null;
		}
		
		Map<String, Object> levelpro = (Map<String, Object>)apMaps.get(FIELD_APLEVEL);
		return levelpro;
	}
	
	
/*	private boolean staMoveHistory(String stamac){
		当前状态查找sta记录
		GetResponse getResponse = client.prepareGet(cindex, stainfo, stamac).execute().actionGet();
		if(!getResponse.isExists()){
			logger.error("staMoveHistory[step1] find stamac:"+stamac+" fail");
			return false;
		}
		
		在stainfo_histrory创建该记录
		String json = getResponse.getSourceAsString();
		IndexResponse indexResponse = client.prepareIndex(cindex, stainfo_history)  
	            .setSource(json)  
	            .execute()  
	            .actionGet();  
		if(indexResponse == null){
			logger.error("staMoveHistory[step2] move stamac:"+stamac+" fail");
			return false;
		} 
		
		stainfo删除该记录
		DeleteResponse deleteResponse = client.prepareDelete(cindex, stainfo, stamac)
		        .execute()
		        .actionGet();
		if(!deleteResponse.isFound()){
			logger.error("staMoveHistory[step3] delete stamac:"+stamac+" fail");
			return false;
		}
		return true;
	}*/
	
	
	/*
	 * sta在N天前的历史访问次数
	 */
	private long staHisFreq(String stamac, String start){
		FilterBuilder stafilter = FilterBuilders.termFilter("sta_mac", stamac);
		FilterBuilder rangefilter = FilterBuilders.rangeFilter("sta_login").lt(start);
		SearchResponse response = client.prepareSearch(cindex)  
	            .setTypes(stainfo_history)  
	            .setSearchType(SearchType.COUNT)  
	            .setPostFilter(FilterBuilders.andFilter(stafilter, rangefilter))
	            .setExplain(true)  
	            .execute()  
	            .actionGet(); 
		
		long num = response.getHits().getTotalHits();
		return num;
	}
	
	private static boolean staAddHistory(String apmac, Map<String, Object> stahisinfo){
		/*在stainfo_histrory创建该记录*/

		IndexResponse indexResponse = client.prepareIndex(cindex, stainfo_history)
//				.setParent(apmac)
	            .setSource(stahisinfo)  
	            .execute()  
	            .actionGet();  
		if(indexResponse == null){
			logger.error("staAddHistory fail, ap["+apmac+"], sta["+(String)stahisinfo.get("sta_mac")+"]");
			return false;
		} 
		
		return true;
	}
//	public static void main(String[] args){
//		// 加载配置
//		try {
//			AgentConfig.getInstance().load();
//		} catch (ConfigurationException e) {
//			System.out.println("load es_agent configuration failed: " + e.getMessage());
//			return;
//		}
//		
//		
//		EsUpdate updater = new EsUpdate("mujob", "apinfo", "stainfo", "stainfo_history");
//		updater.allAps();
//		updater.whichStaApHas("a8.15.4d.0c.bf.01", true);
//		updater.whichStaApHas("a8.15.4d.0c.00.04", true);
		
//		updater.upsertLogin("22.34.56.78", "a7.b7.c7.d7", "2014-8-14T12:00:00");
//		updater.upsertLogin("22.34.56.78", "a6.b6.c6.d6", "2014-8-14T12:00:00");
//		updater.allAps();
//		updater.whichStaApHas("22.34.56.78", true);
//		updater.updateLogout("22.34.56.78", "a7.b7.c7.d7", "2014-8-14T13:00:00");
//		try {
//			Thread.sleep(2000);
//		} catch (InterruptedException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		updater.whichStaApHas("22.34.56.78", true);
//		
//		
//		updater.updateFlow("k2.k2.k3,k4", "g1,g2,g3,g4", 100, 100);
//		try {
//			Thread.sleep(2000);
//		} catch (InterruptedException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		updater.whichStaApHas("k2.k2.k3,k4", true);
//		
//		updater.updateFlow("q1.q2.q3,q4", "g1,g2,g3,g4", 100, 100);
//		try {
//			Thread.sleep(2000);
//		} catch (InterruptedException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		updater.whichStaApHas("k2.k2.k3,k4", true);
//		try {
//			Thread.sleep(2000);
//		} catch (InterruptedException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		updater.whichStaApHas("q1.q2.q3,q4", true);
//	}
}
